﻿cmake_minimum_required(VERSION 2.8)
project(swscale)
file(GLOB lib_hdrs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
file(GLOB lib_asms RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} x86/*.asm)
file(GLOB lib_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.def *.c x86/*.c)
list(FILTER lib_srcs EXCLUDE REGEX ".*_template.c|.*colorspace.c|.*floatimg_cmp.c|.*pixdesc_query.c|.*w64xmmtest.c")

set(CMAKE_DEBUG_POSTFIX "D")

macro(cl_asm)
  foreach(_var ${ARGN})
    list(APPEND lib_objs ${_var}.obj)
	file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${_var} src)
	file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${_var}.obj dst)
    add_custom_command(OUTPUT ${dst}
	  COMMAND cd ARGS ${CMAKE_CURRENT_SOURCE_DIR}/..
	  COMMAND yasm ARGS -I. -P config.asm -f win64 ${src} -o ${dst} MAIN_DEPENDENCY ${_var})
  endforeach()
endmacro()
cl_asm(${lib_asms})

include_directories(.. ../compat ../compat/atomics/win32 x86)
add_definitions(-DHAVE_AV_CONFIG_H)
add_library(${PROJECT_NAME} SHARED ${lib_srcs} ${lib_asms} ${lib_objs})
target_link_libraries(${PROJECT_NAME} ${lib_libs} avutil)
install(FILES ${lib_hdrs} DESTINATION include/ffmpeg/lib${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-config.cmake)

if(BUILD_STATIC)
  add_library(${PROJECT_NAME}S STATIC ${lib_srcs} ${lib_asms} ${lib_objs})
  install(TARGETS ${PROJECT_NAME}S EXPORT ${PROJECT_NAME}S-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(EXPORT ${PROJECT_NAME}S-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}S-config.cmake)
endif()

